package com.example.jpa.repository;

import com.example.jpa.entity.StudentInf;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @author qilongxin
 * @date 2021/8/25 22:56
 */
@Repository
public interface StudentInfRepository extends
        JpaRepository<StudentInf, Long>,
        JpaSpecificationExecutor<StudentInf>,
        QuerydslPredicateExecutor<StudentInf>,
        CustomStudentInfRepository {

    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true, flushAutomatically = true)
    @Query("update StudentInf set age = :age where name = :name")
    Integer updateStudent(@Param("name") String name, @Param("age") Integer age);

}
